package com.carpool.message;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class PassageConfirm {
private static final String SERVLET_URL = "http://169.254.80.238:8080/carpooletservice/Confirm";
	

	public static boolean confirm(int passagerID,int DriverID,int routeID ) {
		boolean result=false;
		URL url = null;
		HttpURLConnection httpurlconnection = null;
		try {
			url = new URL(SERVLET_URL);
			httpurlconnection = (HttpURLConnection) url.openConnection();
			httpurlconnection.setRequestMethod("POST");
			httpurlconnection.setDoOutput(true);
			httpurlconnection.setDoInput(true);
			httpurlconnection.connect();
			DataOutputStream dos = new DataOutputStream(
					httpurlconnection.getOutputStream());
			dos.writeInt(passagerID);
			dos.writeInt(DriverID);
			dos.writeInt(routeID);
			dos.flush();
			dos.close();
			DataInputStream dis = new DataInputStream(
					httpurlconnection.getInputStream());
			result = dis.readBoolean();
		} catch (Exception e) {
			// e.printStackTrace();
			
		} finally {
			if (httpurlconnection != null)
				httpurlconnection.disconnect();
		}

		return result;
	}

}
